package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.pro.enums.permission.enums.ProPermissionAliasEnum;
import com.xbongbong.pro.statistic.enums.StatisticsTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * @ClassName PerformanceOperatorEnum
 * @Description 目标操作枚举
 * @Author mengna.Deng
 * @Date 2022/3/11 14:10
 * @Version 1.0
 */
@Getter
public enum PerformanceOperatorEnum {

    // 新建
    PERFORMANCE_SET("performanceSet","enum.performanceOperator.name.performance_set"),
    // 参数设置
    PARAM_SET("paramSet", "enum.performanceOperator.name.param_set"),
    // 导入
    IMPORT("import", "enum.performanceOperator.name.import"),
    // 编辑
    PERFORMANCE_EDIT("performanceEdit", "enum.performanceOperator.name.performance_edit"),
    // 目标值设置
    PERFORMANCE_OBJECT_SET("performanceObjectSet", "enum.performanceOperator.name.performance_object_set"),
    // 删除
    PERFORMANCE_DELETE("performanceDelete", "enum.performanceOperator.name.performance_delete"),
    // app设置
    APP_SET("appSet", "enum.performanceOperator.name.app_set");

    private String key;
    private String name;

    PerformanceOperatorEnum(String key, String name) {
        this.key = key;
        this.name = name;
    }

    public static List<PerformanceOperatorEnum> getAllEnum() {
        List<PerformanceOperatorEnum> list = new ArrayList<>();
        for (PerformanceOperatorEnum cache : values()) {
            list.add(cache);
        }
        return list;
    }
    public static List<PerformanceOperatorEnum> getByStatisticsType(Integer statisticsType, Set<String> saasPermissions){
        if (!Objects.equals(statisticsType,StatisticsTypeEnum.SYSTEM_STATISTIC.getCode()) &&  !Objects.equals(statisticsType,StatisticsTypeEnum.CUSTOM_STATISTIC.getCode())){
            return null;
        }
        if (!saasPermissions.contains(ProPermissionAliasEnum.PERFORMANCE_OBJECT_SET.getAlias())){
            return null;
        }
        List<PerformanceOperatorEnum> list = new ArrayList<>();
        if (saasPermissions.contains(ProPermissionAliasEnum.PERFORMANCE_SET.getAlias())){
            list.add(PERFORMANCE_EDIT);
        }
        list.add(PERFORMANCE_OBJECT_SET);
        if (Objects.equals(statisticsType, StatisticsTypeEnum.CUSTOM_STATISTIC.getCode()) && saasPermissions.contains(ProPermissionAliasEnum.PERFORMANCE_SET.getAlias())){
            list.add(PERFORMANCE_DELETE);
        }
        return list;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

}
